import org.junit.Test;

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tool {
    @Test
    public void genPropertyList(){
        try {
            File f = new File("E:\\working\\socket\\iot\\BACNet_PropertyType.txt");
//            File f = new File("/Volumes/FileStorageDisk/working/socket/iotp/BACNet_PropertyType.txt");
            InputStreamReader isr = new InputStreamReader(new FileInputStream(f));
            BufferedReader br = new BufferedReader(isr);
            Pattern p1 = Pattern.compile("(?=.+?\\s+)([a-zA-Z]+)(?=\\s+\\=.+?)",Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
            Pattern p2 = Pattern.compile("[\\d]+",Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
            String line;
            while ((line = br.readLine()) != null){
                Matcher m1 = p1.matcher(line);
                Matcher m2 = p2.matcher(line);
                if(m1.find() && m2.find()){
                    System.out.println("cbm1.addElement(new IntegerItem(\"" + m1.group(0) + "(" + m2.group(0) + ")\", " + m2.group(0) + "));");
                }
            }
            br.close();
            isr.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Test
    public void genDatatypeList(){
        try {
            File f = new File("E:\\working\\socket\\iot\\BACNet_DataType.txt");
//            File f = new File("/Volumes/FileStorageDisk/working/socket/iotp/BACNet_DataType.txt");
            InputStreamReader isr = new InputStreamReader(new FileInputStream(f));
            BufferedReader br = new BufferedReader(isr);
            Pattern p1 = Pattern.compile("(?=.+?\\s+)([a-zA-Z]+)(?=\\s+\\=.+?)",Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
            Pattern p2 = Pattern.compile("[\\d]+",Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
            String line;
            while ((line = br.readLine()) != null){
                Matcher m1 = p1.matcher(line);
                Matcher m2 = p2.matcher(line);
                if(m1.find() && m2.find()){
                    System.out.println("cbm2.addElement(new IntegerItem(\"" + m1.group(0) + ": " + m2.group(0) + "\", " + m2.group(0) + "));");
                }
            }
            br.close();
            isr.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
